package com.example.a_java.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.a_java.dto.ContractDetailDTO;
import com.example.a_java.entity.ContractAttachment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 合同附件Mapper接口
 */
@Mapper
public interface ContractAttachmentMapper extends BaseMapper<ContractAttachment> {
    
    /**
     * 查询合同附件列表
     * @param contractId 合同ID
     * @return 附件列表
     */
    @Select("SELECT " +
            "ca.attachment_id AS id, " +
            "ca.file_name AS name, " +
            "ca.file_path AS path, " +
            "ca.file_type AS type, " +
            "ca.file_size AS size, " +
            "ca.upload_time AS uploadTime " +
            "FROM contract_attachment ca " +
            "WHERE ca.is_deleted = 0 AND ca.contract_id = #{contractId} " +
            "ORDER BY ca.upload_time DESC")
    List<ContractDetailDTO.AttachmentDTO> selectAttachmentsByContractId(@Param("contractId") Long contractId);
} 
